﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DemoForHBQ
{
    enum BlockStatus  //枚举定义块的3种状态
    {
        Blank,    //空白
        Black,    //黑色
        White,    //白色 
    }

    /// <summary>
    /// 块对象
    /// </summary>
    class Block
    {
        /// <summary>
        /// 状态
        /// </summary>
        public BlockStatus Status { get; set; }
        //用get set 方法来访问(get)修改(set)私有成员变量


        /// <summary>
        /// 矩阵坐标
        /// </summary>
        public Point Point { get; set; }

        private Rectangle Rectangle
        {
            get { return new Rectangle(Point.Y * 100 + 100, Point.X * 100 + 100, 100, 100); }
            //Point.X,Point.Y为方格坐标标记，rectangle坐标将原扩至合适倍数
            //相当于包含一句Rectangle Rectangle=new Rectangle(Point.Y * 100 + 100, Point.X * 100 + 100, 100, 100)
        }

        public bool Contains(Point point)
        {
            return Rectangle.Contains(point);
        }

        public Block()
        {
            //初始状态空白
            Status = BlockStatus.Blank;
        }

        /// <summary>
        /// 矩阵坐标
        /// </summary>
        /// <param name="point">矩阵坐标(与物理坐标反)</param>
        public Block(Point point)//多态，有坐标的
        {
            //初始状态为空白
            Status = BlockStatus.Blank;
            Point = point;
        }

        /// <summary>
        /// 绘制深浅两种板块
        /// </summary>
        /// <param name="g">画图句柄</param>
        public void Draw(Graphics g)  //在Game里被调用
        {
            //在上面的Rectangle里绘制
            if ((Point.Y + Point.X) % 2 == 0)
            {
                //根据坐标关系，深色块的横纵坐标相加为偶数
                g.DrawImage(Properties.Resources.dark_bg, Rectangle);
            }
            else
            {
                g.DrawImage(Properties.Resources.light_bg, Rectangle);
            }
            //dark_bg,light_bg分别为深色，浅色块的图

            //根据变量block的当前状态，绘制位于这个block对应格子（Rectangle)里的棋子
            switch (Status)
            {
                case BlockStatus.Black:
                    g.DrawImage(Properties.Resources.black_piece, Rectangle);
                    break;
                case BlockStatus.White:
                    g.DrawImage(Properties.Resources.white_piece, Rectangle);
                    break;
                    //black_piece,white_piece分别为黑白棋子图
            }
        }

        /// <summary>
        /// 处理鼠标点击，改变当前块的颜色
        /// </summary>
        /// <param name="IsBlack"></param>
        public void MouseDown(bool IsBlack)
        {
            this.Status = IsBlack ? BlockStatus.Black : BlockStatus.White;
        }



    }
}
